
<?php
/**
 * The template for fetching a post of type Gallery.
 *
 * @package Behold
 * @since Behold 1.0.0
 */
?>
 
<div class="eachpost group">

	<div id="post-<?php the_ID(); ?>" <?php post_class('blgcontent group ');?>>
		<div class="entry-header group">					
			<?php
				$behold_post_format = get_post_format();
				if ( false === $behold_post_format )
				$behold_post_format = 'standard';
			?>
			<h1 class="entry-title format-<?php echo $behold_post_format;?>">
				<?php if ( is_singular() ):
				// single post title should NOT display a phyperlink to itself as per standards.
					the_title();
				else : ?>
					<a class="entry-title-link" href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'Behold' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
				<?php
				endif;
				edit_post_link( '', '', '' ); ?>
			</h1>
		</div>
		
		<?php 
		if ( is_search() ) {
			the_excerpt();
		} else {
			if( is_single() ) {
				the_content();
			} else {
				$behold_images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
				if ( $behold_images ) :
					$total_images = count( $behold_images );
					$behold_image = array_shift( $behold_images );
					$behold_image_img_tag = wp_get_attachment_image( $behold_image->ID, 'thumbnail' );
				?>
				<div class="gallery-thumb">
					<a href="<?php the_permalink(); ?>"><?php echo $behold_image_img_tag; ?></a>
				</div><!-- .gallery-thumb -->

				<p>
					<?php printf( _n( 'This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'Behold' ),
							'href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'Behold' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark"',
							number_format_i18n( $total_images )
						); ?>				
				</p>
				<?php 
				the_excerpt(); 
				endif; # Close of if ( $behold_images)
			} # Close of second else - ie. if not is_single()
		} # Close of first else!
				wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'Behold' ) . '</span>', 'after' => '</div>' ) ); 
		?>
	</div>				
	
	<div class="post-meta group">
			<div class="m-arrow" ></div>
			<div class="publish-time-with-author">								
				<?php behold_posted_at_with_author(); ?>							
			</div>							
			<div class="post-meta-comments">
				<?php 
					behold_get_post_comments();
				?>
			</div>	
			<div class="post-meta-cat">
				<?php behold_get_post_categories();?>
			</div>
			<div class="post-meta-tag">
				<?php behold_get_post_tags();?>
			</div>			
	</div>	<!-- close of post-footer which with post meta -->
</div>